package ListDemo.demo3;

import java.util.ArrayList;

public class test {
    public static void main(String[] args){
        ArrayList<Dog> list = new ArrayList<>();
        // 创建对象
        Hasky hs = new Hasky("jss", 21);
        Teddy td = new Teddy("dkd", 21);
        list.add(td);
        list.add(hs);
        method(list);
        new Swim<Dog>() {
            @Override
            public void swim(Dog hs){
                System.out.println(hs.getName() + "在游泳");
            }
        }.swim(hs);
        

    }
    public static void method(ArrayList<? extends Dog> list){
        for (Dog list2 : list) {
            list2.eat();
        }
    }
}
